# -*- coding: utf-8 -*-
import threading
import os
import tkinter
from tkinter import *
from tkinter import messagebox, ttk


def get_phone_status():
	cmd1 = "adb get-state"
	devices_status = os.popen(cmd1).read().split()[0]
	return devices_status


def teread():
	for i in range(1):
		t = threading.Thread()
		t.start()


def thiker_run():
	try:
		phone_status = get_phone_status()
		if phone_status == 'device':
			root = tkinter.Tk()
			root.title('senseFaceApp')
			tkinter.Label(root, text='性能参数展示', fg='red', font=("黑体", 15, "bold"),).grid(row=0, column=3)
			cpu_t=tkinter.Text(root, height=5, width=30)
			cpu_t.grid(row=1, column=2)
			liulang_t = tkinter.Text(root, height=5, width=40)
			liulang_t.grid(row=1, column=4)
			liulang_t.see(END)
			neicun_t=tkinter.Text(root,height=5,width=30)
			neicun_t.grid(row=3,column=2)
			neicun_t.see(END)
			suji_ev = [50, 100, 150, 200, 300]#这里还原可以增加可以选择的次数
			xing_t = ttk.Combobox(root, values=suji_ev, width=5)
			xing_t.current(0)
			xing_t.grid(row=1,column=6)
			tkinter.Label(root,text='cpu').grid(row=2, column=2)
			tkinter.Label(root,text='参数次数').grid(row=1, column=5)
			tkinter.Label(root,text='流量').grid(row=2, column=4)
			tkinter.Label(root,text='内存').grid(row=6, column=2)
			tkinter.Label(root,text='包名：').grid(row=7, column=1)
			xingneng_baoming=tkinter.Text(root, height=1, width=30)
			xingneng_baoming.grid(row=7, column=2)
			xingneng_btn=tkinter.Button(root, text='开始测试', font=("黑体", 15, "bold"), command=teread)
			xingneng_btn.grid(row=7, column=3)
			tkinter.Label(root, text='启动时间测试', fg='red', height=2, font=("黑体", 15, "bold")).grid(row=8, column=3)

			# test package name
			tkinter.Label(root, text='测试包名').grid(row=9, column=1)
			test_package_name = tkinter.Text(root, height=1, width=30)
			test_package_name.grid(row=9, column=2)

			# test package name Activity
			tkinter.Label(root, text='测试包Activity').grid(row=9, column=3)
			activ_t = tkinter.Text(root, height=1, width=30)
			activ_t.grid(row=9, column=4)

			# test times
			tkinter.Label(root, text='测试次数').grid(row=9, column=5)
			num = [10, 20, 30, 50, 100]
			times_ac = ttk.Combobox(root, values=num, state='readonly', width=5)
			times_ac.current(0)
			times_ac.grid(row=9, column=6)

			# time show
			tkinter.Label(root,text='启动时间展示').grid(row=10,column=1)
			e1 = tkinter.Text(root,width=30,height=10, state="disabled")
			e1.grid(row=10,column=2,padx=20,pady=30)

			# test
			btn_start=tkinter.Button(root,text='测试',font=("黑体", 15, "bold"))
			btn_start.grid(row=10,column=3)

			# Monkey test
			tkinter.Label(root,text='Monkey 测试',fg='red',font=("黑体", 15, "bold")).grid(row=11,column=3)
			tkinter.Label(root,text='测试包名：').grid(row=12,column=1)
			baoming_t1=tkinter.Text(root,height=1,width=30)
			baoming_t1.insert('0.0',0)
			baoming_t1.grid(row=12,column=2)
			tkinter.Label(root,text='随机种子个：').grid(row=12,column=3)
			zhongzi_t=tkinter.Text(root,height=1,width=30)
			zhongzi_t.grid(row=12,column=4)
			zhongzi_t.insert('0.0',0)
			tkinter.Label(root,text='时间间隔：').grid(row=12,column=5)
			suji_event=[500,1000,1500,2000,3000]
			time_t=ttk.Combobox(root,values=suji_event,width=5)
			time_t.current(0)
			time_t.grid(row=12,column=6)
			tkinter.Label(root,text='导航事件百分比：').grid(row=13,column=1)
			danghang_t=tkinter.Text(root,height=1,width=30)
			danghang_t.insert('0.0',0)
			danghang_t.grid(row=13,column=2)
			tkinter.Label(root,text='触摸事件百分比：').grid(row=13,column=3)
			touch_t=tkinter.Text(root,height=1,width=30)
			touch_t.grid(row=13,column=4)
			touch_t.insert('0.0',0)
			tkinter.Label(root,text='滑动事件百分比：').grid(row=14,column=1)
			huadong_t=tkinter.Text(root,height=1,width=30)
			huadong_t.grid(row=14,column=2)
			huadong_t.insert('0.0',0)
			tkinter.Label(root,text='轨迹球事件百分比:').grid(row=14,column=3)
			guiji_t=tkinter.Text(root,height=1,width=30)
			guiji_t.grid(row=14,column=4)
			guiji_t.insert('0.0',0)
			tkinter.Label(root,text='系统按键百分比：').grid(row=15,column=1)
			xitong_t=tkinter.Text(root,height=1,width=30)
			xitong_t.grid(row=15,column=2)
			xitong_t.insert('0.0',0)
			tkinter.Label(root,text='activity之间的切换百分比:').grid(row=15,column=3)
			acti_t=tkinter.Text(root,height=1,width=30)
			acti_t.grid(row=15,column=4)
			acti_t.insert('0.0',0)
			tkinter.Label(root,text='伪随机数:').grid(row=16,column=1)
			event_t=tkinter.Text(root,height=1,width=30)
			event_t.insert('0.0',0)
			event_t.grid(row=16,column=2)
			tkinter.Label(root,text='日志存放路径:').grid(row=16,column=3)
			log_t=tkinter.Text(root,height=1,width=30)
			log_t.grid(row=16,column=4)
			log_t.insert('0.0','F:\\monekey.txt')
			btn_monkey=tkinter.Button(root,text='启动Monkey测试',font=("黑体", 15, "bold"))
			btn_monkey.grid(row=17,column=3)
			root.mainloop()
		else:
			print(phone_status)
			print('设备未连接或者连接异常')

	except Exception as e:
		print("e: " + e)


if __name__ == '__main__':
	thiker_run()

